<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="审核状态">
              <j-dict-select-tag placeholder="请选择审核状态" v-model="queryParam.auditStatus" dictCode="audit_status"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="ID">
              <a-input placeholder="ID" v-model="queryParam.userId"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="昵称">
              <a-input placeholder="请输入昵称" v-model="queryParam.userName"></a-input>
            </a-form-item>
          </a-col>

          <template v-if="toggleSearchStatus">
            <a-col :xl="10" :lg="11" :md="12" :sm="24">
              <a-form-item label="申请时间">
                <j-date :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择开始时间" class="query-group-cust" v-model="queryParam.createTime_begin"></j-date>
                <span class="query-group-split-cust"></span>
                <j-date :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择结束时间" class="query-group-cust" v-model="queryParam.createTime_end"></j-date>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    <div class="table-operator">
      <a-button type="primary" @click="batchAudit('2')">批量通过</a-button>
      <a-button type="primary" @click="batchAudit('3')">批量拒绝</a-button>
    </div>


    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <template slot="textSlot" slot-scope="text">
          <span style="width: 200px">
            {{text}}
          </span>
        </template>
        <template slot="statusSlot" slot-scope="text, record">
          <div v-if="record.auditStatus === '1'" style="color: #169bd5">{{text}}</div>
          <div v-else-if="record.auditStatus === '2'" style="color: #000000">{{text}}</div>
          <div v-else style="color: red">{{text}}</div>
        </template>
        <template slot="fileSlot" slot-scope="text,record">
          <span v-if="record.type=='2'" style="position: relative;margin-left: 5px" @click="openVideo(text)"  >
            <img :src="text+'?x-oss-process=video/snapshot,t_0,f_jpg,w_0,h_0'" :style="{width: '30px',height: '50px'}">
            <img style="width: 25px;height: 25px;position:absolute;z-index: 1;top:50%;left: 50%;transform: translate(-50%, -50%)" src="~@/assets/play.png">
          </span>
          <span v-else>
            <a @click="() => viewFile(text)">查看图片</a>
          </span>
        </template>

        <span slot="action" slot-scope="text, record">
          <a v-if="record.auditStatus=='1'" @click="openBanaccountModal(record)">封号</a>
          <a-divider v-if="record.auditStatus=='1'" type="vertical" />
          <a v-if="record.auditStatus=='1'" @click="bianImMsg(record)">禁言</a>
          <a-divider v-if="record.auditStatus=='1'" type="vertical" />
          <a v-if="record.auditStatus=='1'" @click="dataAudit(record.id,'2')">审核通过</a>
          <a-divider v-if="record.auditStatus=='1'" type="vertical" />
          <a v-if="record.auditStatus=='1'" @click="dataAudit(record.id,'3')">审核拒绝</a>
          <a-popconfirm v-if="record.auditStatus !='1'" title="确定删除吗?" @confirm="() => handleDelete(record.id)">
              <a>删除</a>
            </a-popconfirm>
          <a-divider type="vertical" />
          <a @click="openAuditInfo(record)">自动审核信息</a>
        </span>

      </a-table>
    </div>

    <!-- 视频播放器 -->
    <a-modal v-model="videoVisible" :width="800" @cancel="videoClose" :footer="null" destroyOnClose>
      <div style="margin-top: 20px;height: 1000px">
        <vue-core-video-player
          :loop="false"
          autoplay="false"
          style="width: 100%;height: 100%"
          :src="videoUrl"
        ></vue-core-video-player>
      </div>
    </a-modal>
    <BanaccountModal ref="BanaccountModal" @ok="modalFormOk"></BanaccountModal>
    <ViewFileModel ref="ViewFileModel"></ViewFileModel>
    <AuditInfo ref="AuditInfo"></AuditInfo>
  </a-card>
</template>

<script>

  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import ViewFileModel from '@/views/xiny/common/ViewFileModel'
  import { getAction } from '@/api/manage'
  import BanaccountModal from '@/views/xiny/security/banaccount/modules/BanaccountModal'
  import AuditInfo from '../../AuditInfo'
  import VueCoreVideoPlayer from 'vue-core-video-player'

  export default {
    name: 'CommunityInfoList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      ViewFileModel,
      BanaccountModal,
      AuditInfo
    },
    data () {
      return {
        description: '社区表管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'ID',
            align:"center",
            dataIndex: 'userId'
          },
          {
            title:'昵称',
            align:"center",
            dataIndex: 'userName'
          },
          {
            title:'动态内容',
            align:"center",
            dataIndex: 'textContent',
            width: 600
          },
          {
            title:'图片/视频',
            align:"center",
            dataIndex: 'fileUrl',
            scopedSlots: { customRender: 'fileSlot' }
          },
          {
            title:'审核状态',
            align:"center",
            dataIndex: 'auditStatus_dictText',
            scopedSlots: { customRender: 'statusSlot' }
          },
          {
            title:'申请时间',
            align:"center",
            dataIndex: 'createTime'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:260,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/community/communityInfo/list",
          delete:"/community/communityInfo/delete"
        },
        dictOptions:{},
        superFieldList:[],

        videoVisible:false,
        videoUrl:"",
      }
    },
    created() {
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      //查看审核内容
      openAuditInfo(record){
        this.$refs.AuditInfo.visible=true;
        this.$refs.AuditInfo.getAuditInfo(record.id,"2");//2代表动态审核
      },
      //封号
      openBanaccountModal(record){
        var obj={};
        obj.roomMsgId = record.id;
        obj.womanName = record.userName;
        obj.womanId = record.userId;
        obj.whatType="3";//3代表动态发布
        obj.type="1";//1代表封号类型

        this.$refs.BanaccountModal.edit(obj);
        this.$refs.BanaccountModal.title = "封号";
        this.$refs.BanaccountModal.disableSubmit = false;
      },

      //禁言
      bianImMsg(record){
        var obj={};
        obj.roomMsgId = record.id;
        obj.womanName = record.userName;
        obj.womanId = record.userId;
        obj.whatType="3";//3代表动态发布
        obj.type="2";//2代表禁言类型

        this.$refs.BanaccountModal.edit(obj);
        this.$refs.BanaccountModal.title = "禁言";
        this.$refs.BanaccountModal.disableSubmit = false;
      },
      //批量审核
      batchAudit(type){
        if(this.selectedRowKeys.length==0){
          this.$message.warning("请至少选择一条记录进行审核");
          return;
        }
        for (let i = 0; i < this.selectionRows.length; i++) {
          if(this.selectionRows[i].auditStatus!=1){
            this.$message.warning("只能选择”待审核“的数据操作");
            return;
          }
        }
        this.dataAudit(this.selectedRowKeys.join(","),type);
      },
      //审核
      dataAudit(ids,type){
        this.loading = true;
        getAction('/community/communityInfo/communityAudit', {ids: ids,type:type}).then(({success, result, message}) => {
          if (success) {
            this.loadData();
            this.onClearSelected();
            this.$message.success(message)
          } else {
            this.$message.warning(message)
          }
        }).finally(() => this.loading = false)
      },


      //关闭播放器
      videoClose(){
        this.videoUrl = "";
        this.videoVisible = false;
      },
      //打开
      openVideo(url){
        this.videoUrl = url;
        this.videoVisible = true;
      },

      //查看文件
      viewFile(fileUrl){
        var url=[];
        if(fileUrl){
          var jsonArray = JSON.parse(fileUrl);
          jsonArray.forEach((item,index)=>{
            url.push(item.imgUrl);
          })
        }
        this.$refs.ViewFileModel.fileUrl=url;
        this.$refs.ViewFileModel.title="查看图片";
        this.$refs.ViewFileModel.visible=true;
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>